Skip to content

TST: Extend timedelta64 arithmetic tests to TimedeltaArray #23642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 20, 2018

Conversation

jbrockmendel
Copy link
Member

A handful of non-test changes to make the tests pass, all non-test changes are strictly necessary.

Some of the tests are not yet extended, as making the TDA case work will require more invasive changes.

@pep8speaks
Copy link

Hello @jbrockmendel! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Nov 13, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@2af56d4). Click here to learn what that means.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #23642   +/-   ##
=========================================
  Coverage          ?   92.29%           
=========================================
  Files             ?      161           
  Lines             ?    51489           
  Branches          ?        0           
=========================================
  Hits              ?    47520           
  Misses            ?     3969           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.68% <94.11%> (?)
#single 42.32% <67.64%> (?)
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.48% <100%> (ø)
pandas/core/indexes/timedeltas.py 89.18% <85.71%> (ø)
pandas/core/arrays/timedeltas.py 96.44% <96.15%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2af56d4...2df7d65. Read the comment docs.

@gfyoung gfyoung added Testing pandas testing functions or related to the test suite Timedelta Timedelta data type labels Nov 13, 2018
@@ -288,6 +317,21 @@ def _evaluate_with_timedelta_like(self, other, op):

return NotImplemented

__mul__ = _wrap_tdi_op(operator.mul)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use the already existing machinery and simply implement this _create_arithmetic_method
and a limited form of:

@classmethod
    def _add_arithmetic_ops(cls):

otherwise you have different styles here than elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this pattern in plenty of places: nattype, Timedelta, field accessors TDA/DTA/PA, ... Using the classmethod in this context doesn't add anything except a layer of indirection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but that'st the point, we should be using this here as this IS using the mixin that implements this. This is creating yet another pattern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this IS using the mixin that implements this

No, it isn't. It inherits from ExtensionOpsMixin to use _add_comparison_comps, NOT _add_arithmetic_ops. In fact if were to try to use _add_arithmetic_ops that would be working at cross-purposes with _add_datetimelike_methods, which specifically implements add/sub-like methods.

I'm as big a fan of internal consistency and de-duplication as the next guy, but this isn't the place to make that stand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback ok for now?

(anyway, I think the goal is to rework this a bit at some point, to not wrap TimedeltaIndex here, rather the other way around)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal is to rework this a bit at some point, to not wrap TimedeltaIndex here, rather the other way around

Correct

__rmul__ = __mul__
__truediv__ = _wrap_tdi_op(operator.truediv)
__floordiv__ = _wrap_tdi_op(operator.floordiv)
__rfloordiv__ = _wrap_tdi_op(ops.rfloordiv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are you implmenting rfloordiv but not rdiv / rtruediv?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very specifically implementing only the methods needed to extend the affected tests. I'll double-check why i couldn't extend tests for rdiv and rtruediv

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel any findings here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT we don't have test cases for the other methods, at least not in tests.arithmetic.test_timedelta64. I've scoured the other test files to centralize arithmetic tests, but it's conceivable I've missed some.

We definitely need such tests, but I'd rather do that in a dedicated PR, and would prefer not to implement the methods here without the corresponding tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need such tests, but I'd rather do that in a dedicated PR, and would prefer not to implement the methods here without the corresponding tests.

+1

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor question for clarification

@@ -288,6 +317,21 @@ def _evaluate_with_timedelta_like(self, other, op):

return NotImplemented

__mul__ = _wrap_tdi_op(operator.mul)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback ok for now?

(anyway, I think the goal is to rework this a bit at some point, to not wrap TimedeltaIndex here, rather the other way around)

__rmul__ = __mul__
__truediv__ = _wrap_tdi_op(operator.truediv)
__floordiv__ = _wrap_tdi_op(operator.floordiv)
__rfloordiv__ = _wrap_tdi_op(ops.rfloordiv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel any findings here?

DatetimeArrayMixin as DatetimeArray)


def get_upcast_box(box, vector):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something similar is not needed in the other files in tests/arithmetic ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we'll want something like this, probably put it next to tm.box_expected. After this I'll end up rebasing #23734 and see if this can be re-used in the other files. There are enough special cases that it isn't obvious off the top of my head.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you rebase off of #23734? isn't this basically box_expected with another arg? there are a LOT of helpers out there. too many.....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this has been rebased. This is about determining what box to use when we are parametrizing over two box types. I agree it may be nice to cut down on the helpers; in fact I think we may be able to get rid of tm.box_expected if we're lucky (fixing the transpose thing...)

@jreback
Copy link
Contributor

jreback commented Nov 17, 2018

can you rebase

@jbrockmendel
Copy link
Member Author

Updated to use box_with_array instead of box_with_timedelta

@jbrockmendel
Copy link
Member Author

Following this I think there will be just one more round of DTA/TDA arithmetic test PRs. Almost there.

@jbrockmendel
Copy link
Member Author

Following this I think there will be just one more round of DTA/TDA arithmetic test PRs

The "one more" this was referring to was #23789, but I forgot one other: the follow-up discussed above to implement+test rdiv, rtruediv, etc. I'm pretty psyched to have this all wrapped up.

@jbrockmendel
Copy link
Member Author

gentle ping. follow-up waiting in the wings

@jorisvandenbossche jorisvandenbossche merged commit 99df7da into pandas-dev:master Nov 20, 2018
@jorisvandenbossche
Copy link
Member

@jbrockmendel Thanks!

@jbrockmendel jbrockmendel deleted the pre-arith branch November 20, 2018 20:05
thoo added a commit to thoo/pandas that referenced this pull request Nov 21, 2018
…fixed

* upstream/master:
  TST: Extend timedelta64 arithmetic tests to TimedeltaArray (pandas-dev#23642)
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants